package com.redhat.auth.web.account;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dayatang.domain.InstanceFactory;
import com.dayatang.querychannel.service.QueryChannelService;
import com.redhat.auth.application.AccountApplication;
import com.redhat.auth.domain.Account;
import com.redhat.auth.domain.BizSystem;
import com.redhat.auth.domain.BizSystemBinding;
import com.redhat.redwork.widget.grid.AbstractGridModel;
import com.redhat.redwork.widget.grid.Order;

/**
 * 添加系统绑定的GridModel 规则：默认不加载任何数据 传入accountId时，返回所有此ID未绑定的BizSystem
 * 
 * @author lingen.liu
 * 
 */
@Component
@Transactional
public class AccountSystemBindingGridModel extends
		AbstractGridModel<BizSystem, Account> {

	private long count;

	@Autowired
	private AccountApplication accountApplication;

	private static QueryChannelService queryChannel;

	public static QueryChannelService getQueryChannel() {
		if (queryChannel == null) {
			queryChannel = InstanceFactory
					.getInstance(QueryChannelService.class);
		}
		return queryChannel;
	}

	public static void setQueryChannel(QueryChannelService queryChannel) {
		AccountSystemBindingGridModel.queryChannel = queryChannel;
	}

	@Override
	public Long count(Account search) {
		return count;
	}

	@Override
	public Account getCriteriaObject() {
		return new Account();
	}

	@Override
	public List<BizSystem> list(Account search, int page, int pageSize,
			Order order) {
		List<BizSystem> systems = accountApplication
				.listBizSystemNotBindingAccount(search, page, pageSize);
		setCount(systems.size());
		return systems;
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public AccountApplication getAccountApplication() {
		return accountApplication;
	}

	public void setAccountApplication(AccountApplication accountApplication) {
		this.accountApplication = accountApplication;
	}

}
